import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:meal/components/group/all.dart';
import 'package:meal/components/group/proceed.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

class GroupManage extends StatefulWidget {
  const GroupManage({Key? key}) : super(key: key);

  @override
  State<GroupManage> createState() => _GroupManageState();
}

class _GroupManageState extends State<GroupManage> with SingleTickerProviderStateMixin {
  late TabController _controller;

  List<String> tabs = ['全部活动', '进行中(3)'];

  PreferredSizeWidget get bottom {
    return PreferredSize(
        preferredSize: const Size.fromHeight(Sizes.default50),
        child: Container(
          decoration: const BoxDecoration(
            color: Colors.white,
          ),
          height: Sizes.default50,
          alignment: Alignment.center,
          child: ToolsUtils.getClientTabBar(tabs, _controller),
        ));
  }

  @override
  void initState() {
    _controller = TabController(length: tabs.length, vsync: this);
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
        appBar: ToolsUtils.getDefaultBrnAppBar('团购活动', bottom: bottom),
        body: TabBarView(
          controller: _controller,
          children: const [AllGroup(), ProceedGroup()],
        ),
        bottomNavigationBar: SafeArea(
          top: false,
          child: Container(
            height: Sizes.default50,
            alignment: Alignment.centerLeft,
            decoration: const BoxDecoration(color: Colors.white),
            child: Row(children: bottomWidget()),
          ),
        ));
  }

  List<Widget> bottomWidget() {
    return [
      Expanded(
          child: Center(
              child: InkWell(
        onTap: () {
          Get.toNamed(RouteGet.groupAdd);
        },
        child: Text.rich(TextSpan(children: [
          WidgetSpan(
              child: ToolsUtils.getUrlSvg(
                  'https://cdn7.axureshop.com/demo/1525603/images/团购管理/u3041.svg',
                  width: Sizes.default13,
                  height: Sizes.default13)),
          TextSpan(
              text: '创建',
              style: StylesUtils.customTextStyle(
                  color: ColorsUtils.color797, fontSize: Sizes.default15))
        ])),
      ))),
      Expanded(
          child: Center(
              child: InkWell(
        onTap: () {
          Get.toNamed(RouteGet.groupWriteOff);
        },
        child: Text.rich(TextSpan(children: [
          WidgetSpan(
              child: ToolsUtils.getUrlSvg(
                  'https://cdn7.axureshop.com/demo/1525603/images/团购管理/u3043.svg',
                  width: Sizes.default13,
                  height: Sizes.default13)),
          TextSpan(
              text: '核销',
              style: StylesUtils.customTextStyle(
                  color: ColorsUtils.color797, fontSize: Sizes.default15))
        ])),
      ))),
      Expanded(
          child: Center(
              child: InkWell(
        onTap: () {
          Get.toNamed(RouteGet.groupOrderList);
        },
        child: Text.rich(TextSpan(children: [
          WidgetSpan(
              child: ToolsUtils.getUrlSvg(
                  'https://cdn7.axureshop.com/demo/1525603/images/团购管理/u3044.svg',
                  width: Sizes.default13,
                  height: Sizes.default13)),
          TextSpan(
              text: '订单',
              style: StylesUtils.customTextStyle(
                  color: ColorsUtils.color797, fontSize: Sizes.default15))
        ])),
      ))),
    ];
  }
}
